/* Copyright (c) 2009 SpringShowcase, Inc.
 * All right reserved.
 * http://code.google.com/p/springshowcase/
 * This software is the confidential and proprietary information of BeyondWeb
 * , Inc. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license agreement
 * you entered into with BeyondWeb.
 *
 * Revision History
 * Author              Date             Description
 * ------------------   --------------    ------------------
 *  taeki.kim           2010. 3. 31.        
*/
package org.springshowcase.core.commons.config;

import java.util.Enumeration;
import java.util.Properties;

import org.apache.commons.configuration.PropertiesConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;

// TODO: Auto-generated Javadoc
/**
 * The Class Configuration.
 */
public class Configuration extends PropertiesConfiguration implements
		InitializingBean {

	// ---------------------------------------------------------------------
	// Class Variable Declaration
	// ---------------------------------------------------------------------
	/** The Constant logger. */
	private static final Logger logger = LoggerFactory
			.getLogger(Configuration.class);

	/** The properties. */
	private Properties properties;

	// ---------------------------------------------------------------------
	// Constructor Method Declaration
	// ---------------------------------------------------------------------
	/**
	 * Instantiates a new common configuration.
	 */
	public Configuration() {
	}

	// ---------------------------------------------------------------------
	// DI Method (setter,getter) Declaration
	// ---------------------------------------------------------------------
	/**
	 * Sets the properties.
	 * 
	 * @param properties
	 *            the new properties
	 */
	public void setProperties(Properties properties) {
		this.properties = properties;
	}

	// ---------------------------------------------------------------------
	// this Method (public/private) Declaration
	// ---------------------------------------------------------------------
	// ---------------------------------------------------------------------
	// interface implement Method (public/private) Declaration
	// ---------------------------------------------------------------------
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
	 */
	public void afterPropertiesSet() {
		StringBuffer elements = new StringBuffer();

		if (this.properties != null) {
			Enumeration keys = this.properties.propertyNames();
			elements
					.append("\n ============= dispay config data =============");

			while (keys.hasMoreElements()) {
				String key = (String) keys.nextElement();
				String value = this.properties.getProperty(key);
				elements.append("\n").append("[" + key + "] : " + value);
				super.setProperty(key, value);
			}
		} else {
			elements.append("\n ============= no config data =============");
		}
		logger.info(elements.toString());
		// 기존 데이터 삭제
		this.properties = null;
		elements = null;
	}

	// ---------------------------------------------------------------------
	// abstract implement Method (public/private) Declaration
	// ---------------------------------------------------------------------
	// ---------------------------------------------------------------------
	// abstract Method (public/private) Declaration
	// ---------------------------------------------------------------------

}
